package leetcode;

import java.util.Stack;

public class Offer06 {
    public int[] reversePrint(ListNode head) {
        Stack<Integer> stack = new Stack<Integer>();
        for(;head !=null;head=head.next) {
            stack.push(head.val);
        }
        int[] array = new int[stack.size()];
        for (int i=0;!stack.isEmpty();i++) {
            array[i] = stack.pop();
        }
        return array;
    }

    public class ListNode {
        int val;
        ListNode next;
        ListNode(int x) { val = x; }
    }
}
